package com.kuang.singleton;

//单例模式的学习
//dcl懒汉式  也就是双重检测
public class SingletonDemo03 {
    //1.私有化构造器
    private SingletonDemo03() {
    }
    //2。类初始化的时候，不立即这个对象
    private static SingletonDemo03 instance ;
    //3.提供获取该对象的方法，
    public static SingletonDemo03 getSingletonDemo03(){
        if (instance==null){
            synchronized (SingletonDemo03.class){
                if (instance==null){
                    instance = new SingletonDemo03();
                }
            }
        }
        return instance;
    }
}


class SingletonDemo03Test{
    public static void main(String[] args) {
        SingletonDemo01 instance1 = SingletonDemo01.getSingletonDemo01();
        SingletonDemo01 instance2 = SingletonDemo01.getSingletonDemo01();

        System.out.println(instance1==instance2);//true
    }
}

